package org.xq.shop.maxaishop.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xq.shop.maxaishop.entity.XqVegeimg;
import org.xq.shop.maxaishop.service.XqVegeimgService;
import org.xq.shop.maxaishop.util.JsonRes;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (XqVegeimg)表控制层
 *
 * @author makejava
 * @since 2021-06-16 17:08:32
 */
@Api( tags = "商品详情")
@RestController
@RequestMapping("xqVegeimg")
public class XqVegeimgController {
    /**
     * 服务对象
     */
    @Resource
    private XqVegeimgService xqVegeimgService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("根据主键查询单个系统用户")
    @ApiImplicitParam(name = "id", value = "详情id", required=true,paramType="query" )
    @GetMapping("selectOne")
    public XqVegeimg selectOne(Integer id) {
        return this.xqVegeimgService.queryById(id);
    }

    /**
     * 商品详情
     * @param cid
     * @return
     */
    @ApiOperation("查询每个商品详情图")
    @ApiImplicitParam(name = "cid", value = "商品id", required=true,paramType="query" )
    @PostMapping("queryByCid")
    public Object queryByCid(Integer cid){
        List<XqVegeimg> xqVegeimgs = this.xqVegeimgService.queryByCid(cid);
        return JSON.toJSON(xqVegeimgs);
    }
    @ApiOperation("添加商品详情图")
    @PostMapping("insert")
    public Map insert(XqVegeimg xqVegeimg){
        XqVegeimg insert = this.xqVegeimgService.insert(xqVegeimg);
        if (insert!=null){
            return JsonRes.success(insert);
        }else {
           return JsonRes.failure(null);
        }

    }
}
